--require "MainScene"
Dialog={}
DialogFunc={}
DialogFunc.__index = DialogFunc
setmetatable(Dialog, DialogFunc)

DialogFunc.create = function(self, title, msg, target)
  local l = {}
  setmetatable(l, DialogFunc)
  l.target = target
  l.node = CCBReader:load("CancelOkDialog.ccbi")
  setObjectExtTable(l.node:getChildByTag(1111), l)
  
  setObjectExtTable(l.node:getChildByTag(1112), l)
  setObjectExtTable(l.node:getChildByTag(1113), l)
  
  TypeCast(l.node:getChildByTag(1010), "CCLabelTTF"):setString(title)
  TypeCast(l.node:getChildByTag(1011), "CCLabelTTF"):setString(autoEnter(msg, 45))

  --setTouchEnabledAll(target.node, false)
  --target.node:setVisible(false)
  return l 
end

DialogFunc.onClose = function(self, node, event)
  --node:getParent():getParent():removeChild(node:getParent(), true)
  local metaFunc = getmetatable(self.target)
  if metaFunc["onConfirm"]~=nil then
    metaFunc["onConfirm"](self.target, self, false)
  end
end
DialogFunc.onCancel = function(self, node, event)
  --node:getParent():getParent():removeChild(node:getParent(), true)
  local metaFunc = getmetatable(self.target)
  if metaFunc["onConfirm"]~=nil then
    metaFunc["onConfirm"](self.target, self, false)
  end
end
DialogFunc.onOk = function(self, node, event)
  local metaFunc = getmetatable(self.target)
  if metaFunc["onConfirm"]~=nil then
    metaFunc["onConfirm"](self.target, self, true)
  end
end

